package com.midea.ai.air.ui.home.fragment;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.midea.ai.air.R;
import com.midea.ai.air.common.BaseFragment;
import com.midea.ai.air.common.ConsVal;
import com.midea.ai.air.ui.home.ActivityNotSlip;
import com.midea.ai.air.ui.home.adapter.ViewPagerAdapter;
import com.midea.ai.air.utils.JumpUtils;

/**
 * Created by ouyangdi on 2015/12/15.
 * 首页顶部Fragment
 */
public class HomeTopNavFragment extends BaseFragment implements View.OnClickListener{
    private TabLayout mTopTab;
    private ViewPager mViewPager;
    ViewPagerAdapter mViewPagerAdapter;
    private ImageView mIvEditRoom;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_top_nav_home, container, false);
        initAdapter();
        initView(view);
        return view;
    }

    /**
     * 初始化数据
     */
    private void initAdapter() {
        mViewPagerAdapter = new ViewPagerAdapter(getActivity().getSupportFragmentManager());
        for(int i=0; i<10; i++) {
            mViewPagerAdapter.addFrag(new TopTabFragment(), "主卧");
        }
    }

    private void initView(View view) {
        mViewPager = (ViewPager)view.findViewById(R.id.viewPager_top_nav);
        mViewPager.setAdapter(mViewPagerAdapter);

        mTopTab = (TabLayout)view.findViewById(R.id.top_tab_home);
        mTopTab.setupWithViewPager(mViewPager);

        mIvEditRoom = (ImageView)view.findViewById(R.id.iv_room_setting);
        mIvEditRoom.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_room_setting:
                JumpUtils.toPage(getActivity(), getResources().getString(R.string.air_home_edit_room),
                        getResources().getString(R.string.air_main_home), ConsVal.ACTIVITY_TAG_EDIT_ROOM, ActivityNotSlip.class);
                break;
        }
    }
}
